package com.yootk.server;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class EchoServer {
    public static void main(String[] args) throws Exception{
        ServerSocket serverSocket = new ServerSocket(9999);
        Socket client = serverSocket.accept();
        Scanner scanner = new Scanner(client.getInputStream());
        PrintStream out = new PrintStream(client.getOutputStream());
        boolean flag = true;
        while (flag){
            if (scanner.hasNext()){
                String value = scanner.next().trim();
                if (value.equalsIgnoreCase("exit")){
                    out.println("【EchoServer】信息服务交互完毕，已经断开与服务器的连接。");
                    flag = false;
                    break;
                }
                out.println("ECHO:" + value);
            }
        }
        serverSocket.close();
    }
}
